﻿using Md.Api.Model;
using Md.Api.Model.Manage.MdProductOrder.Request;
using Md.Api.Service.Manage.MdProductOrder;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 产品订单
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/md/productOrder")]
public class MdProductOrderController : ControllerBase
{
    /// <summary>
    /// 通过订单编号删除订单服务
    /// </summary>
    public DeleteMdProductOrderByIdService deleteMdProductOrderByIdService { get; set; }
    /// <summary>
    /// 通过订单编号删除订单
    /// </summary>
    /// <param name="orderIds">订单编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{orderIds}")]
    public async Task<ResponseMessageModel> DeleteMdProductOrderById(string orderIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteMdProductOrderByIdModel();

        model.OrderIds = orderIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteMdProductOrderByIdService.Execute(model));
    }

    /// <summary>
    /// 添加订单服务
    /// </summary>
    public InsertMdProductOrderService insertMdProductOrderService { get; set; }
    /// <summary>
    /// 添加订单
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> InsertMdProductOrder([FromBody] RequestInsertMdProductOrderModel model)
    {
        return await Task.Run(() => insertMdProductOrderService.Execute(model));
    }

    /// <summary>
    /// 通过订单编号更新订单服务
    /// </summary>
    public UpdateMdProductOrderByIdService updateMdProductOrderByIdService { get; set; }
    /// <summary>
    /// 通过订单编号更新订单
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateMdProductOrderById([FromBody] RequestUpdateMdProductOrderByIdModel model)
    {
        return await Task.Run(() => updateMdProductOrderByIdService.Execute(model));
    }

    /// <summary>
    /// 通过订单编号获取订单详情服务
    /// </summary>
    public GetMdProductOrderByIdService getMdProductOrderByIdService { get; set; }
    /// <summary>
    /// 通过订单编号获取订单详情
    /// </summary>
    /// <param name="orderId">订单编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{orderId}")]
    public async Task<ResponseMessageModel> GetMdProductOrderById(long orderId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetMdProductOrderByIdModel();

        model.OrderId = orderId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdProductOrderByIdService.Execute(model));
    }

    /// <summary>
    /// 分页获取订单列表服务
    /// </summary>
    public GetMdProductOrderPageListService getMdProductOrderPageListService { get; set; }
    /// <summary>
    /// 分页获取订单列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetMdProductOrderPageList([FromBody] RequestGetMdProductOrderPageListModel model)
    {
        return await Task.Run(() => getMdProductOrderPageListService.Execute(model));
    }
}
